pp108 : addItemBefore Method

addItemBefore Method


This method adds an item before the specified tree Item.

Syntax


oNewItem = treeNode.addItemBefore(oItemDefinition, oNextElement)

Parameters

Parameter

Description

oItemDefinition

Required. Object that points to an XMLDOM object that contains the item to be added in the tree node.

oNextElement

Required. Object that denotes the tree item before which the new item is to be added.


Return Value


Returns the tree item of the new item that is added in the tree.

Remarks


An item is added to the tree only if the item definition is defined in the tree schema. If such an item is not present, the addSchemaItem method is used to add the schema definition for the item dynamically to the tree.

If the oNextElement parameter is not specified, then the item will be added as a child to the selected node.

Example


The following example shows how the above method is used.

<!-- Template of the item to be added to the tree -->
<script type="cordys/xml" id="newItemTemplate">
    <Favourites>
        <id>favourite</id>
        <description>My Favourites</description>
        <caption>Favourites</caption>
    </Favourites>
</script>
//Function that adds item to the existing tree
function addNewItem()
{
   //Add an item, that depends on the new schema
   var newItem = cordys.cloneXMLDocument(newItemTemplate.XMLDocument);

   //Add the item from the selected node, before the selected node
   sampletree.getSelectedItem().addItemBefore(newItem, sampletree.getSelectedItem());
}

See Also


tree, treeSchema, addSchemaItem